package put.cs.two.tsp.experiments;

import java.util.ArrayList;
import java.util.List;

import put.cs.two.to.tsp.calculators.base.AbstractExperiment;
import put.cs.two.to.tsp.calculators.base.TSPSolutionChangedListener;
import put.cs.two.to.tsp.models.NodeSet;
import put.cs.two.to.tsp.models.TSPSolution;
import put.cs.two.to.tsp.visualization.Visualizator;

public class GreedyExperiment extends AbstractExperiment {

    @Override
    public TSPSolution doWork(NodeSet nodeSet) {
        AbstractExperiment experimentNN = new GreedyNearestNeighbourSearchExperiment();
        setupExperiment(experimentNN);
        TSPSolution best = experimentNN.doWork(nodeSet);
        // System.out.println(best);

        AbstractExperiment experimentCE = new GreedyCycleExtensionSearchExperiment();
        setupExperiment(experimentCE);
        best = experimentCE.doWork(nodeSet);
        System.out.println(best);

        return null;
    }

    private void setupExperiment(AbstractExperiment experiment) {
        List<TSPSolutionChangedListener> listeners = new ArrayList<TSPSolutionChangedListener>();

        listeners.add(Visualizator.getVisualizatorPanel());
        // statistics listener
        // output listener

        for (TSPSolutionChangedListener listener : listeners) {
            experiment.addTSPSolutionChangedListener(listener);
        }
    }
}
